package eureka;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;

import static org.springframework.security.config.Customizer.withDefaults;

@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication {

    public static final void main(String[] args) {
        SpringApplication.run(EurekaApplication.class, args);
    }

    // opt client auth 401
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
                .authorizeRequests().anyRequest().authenticated()
                .and()
                .httpBasic(withDefaults())
                .formLogin(withDefaults())
                .csrf().ignoringAntMatchers("/eureka/**")
        ;
        return http.build();
    }
}
